#!/bin/bash
if which ossmix > /dev/null 2>&1; then
    mix=ossmix # for oss
else
    mix=amixer # for alsa, default
fi

if which notify-send > /dev/null 2>&1; then
    alert="notify-send -t 1000"
else
    alert=echo
fi

case $mix in 
    amixer)
        MASTER_STATUS=`$mix get Master | tail -n 1 | awk '{print $7}'| cut -c 3`
        PCM_STATUS=`$mix get Master | tail -n 1 | awk '{print $7}'| cut -c 3`
        if [ $MASTER_STATUS = "n" ]; then
            $mix set Master mute
        else
            $mix set Master unmute
        fi
        if [ $PCM_STATUS = "n" ]; then
            $mix set PCM mute
            $alert -i /home/razone/.icons/myicon/volume-mute.png "无声模式"
        else
            $mix set PCM unmute
            $alert -i /home/razone/.icons/myicon/volume-max.png "有声模式"
        fi
        exit 0 
        ;;
    ossmix)
        vol=`$mix | grep '^vol ' | awk '{print $4}' | awk -F")" '{print $1}'`
        pcm=`$mix | grep '^pcm ' | awk '{print $4}' | awk -F")" '{print $1}'`
        if [ $vol = "0:0" -a $pcm = "0:0" ]; then
            $mix vol 30
            $mix pcm 30
            $alert -i /home/razone/.icons/myicon/volume-max.png "切换至有声模式"
        else
            $mix vol 0:0
            $mix pcm 0:0
            $alert -i /home/razone/.icons/myicon/volume-mute.png "切换至无声模式"
        fi
        ;;
esac

